﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace GxFramework
{
    static public class SettingManager
    {
        static ISettingHandler _handler;
        static public ISettingHandler settingHandler
        {
            get
            {
                if (null == _handler)
                    _handler = new DefaultSettingHandler();
                return _handler;
            }
            set 
            {
                if (null == value)
                    return;
                _handler = value; 
            }
        }
        static public bool Load()
        {
            return settingHandler.Load();
        }
        static public bool Save()
        {
            return settingHandler.Save();
        }
        static public bool HasKey(string key)
        {
            return settingHandler.HasKey(key);
        }
        static public void Remove(string key)
        {
            settingHandler.Remove(key);
        }
        static public void RemoveAll()
        {
            settingHandler.RemoveAll();
        }

        static public bool GetBool(string key, bool defaultValue)
        {
            return settingHandler.GetBool(key,defaultValue);
        }
        static public bool GetBool(string key)
        {
            return settingHandler.GetBool(key,false);
        }
        static public int GetInt(string key, int defaultValue)
        {
            return settingHandler.GetInt(key,defaultValue);
        }
        static public int GetInt(string key)
        {
            return settingHandler.GetInt(key,0);
        }
        static public float GetFloat(string key, float defaultValue)
        {
            return settingHandler.GetFloat(key,defaultValue);
        }
        static public float GetFloat(string key)
        {
            return settingHandler.GetFloat(key,0f);
        }
        static public string GetString(string key, string defaultValue)
        {
            return settingHandler.GetString(key,defaultValue);
        }
        static public string GetString(string key)
        {
            return settingHandler.GetString(key,null);
        }
        static public object GetObject(string key, Type type, object defaultValue)
        {
            return settingHandler.GetObject(key,type,defaultValue);
        }
        static public object GetObject(string key, Type type)
        {
            return settingHandler.GetObject(key, type, null);
        }
        static public T GetObject<T>(string key, T defaultValue)
        {
            if (HasKey(key))
                return (T)settingHandler.GetObject(key,typeof(T),defaultValue);
            return defaultValue;
        }
        static public T GetObject<T>(string key)
        {
            var defaultValue = default(T);
            if (HasKey(key))
                return (T)settingHandler.GetObject(key, typeof(T), defaultValue);
            return defaultValue;
        }

        

        static public void SetBool(string key, bool value)
        {
            settingHandler.SetBool(key,value);
        }
        static public void SetInt(string key, int value)
        {
            settingHandler.SetInt(key, value);
        }
        static public void SetFloat(string key, float value)
        {
            settingHandler.SetFloat(key, value);
        }
        static public void SetString(string key, string value)
        {
            settingHandler.SetString(key, value);
        }
        static public void SetObject(string key, object value)
        {
            settingHandler.SetObject(key, value);
        }
        static public void SetObject<T>(string key, T value)
        {
            settingHandler.SetObject(key, value);
        }
    }
}